
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>交易密码</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <!--标准mui.css-->
    <link rel="stylesheet" href="__PUBLIC__/css/mui.min.css">
    <!--App自定义的css-->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/app.css" />
    <script type="text/javascript" src="__PUBLIC__/js/jquery-3.2.1.min.js"></script>
    <script src="__PUBLIC__/layer_mobile/layer.js"></script>
</head>
<body>
<header class="mui-bar mui-bar-nav">
    <a onclick="dump('{:U('ZhangHuAnQuan')}')" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <script>
        //url跳转
        function dump(url) {
            location.href=url
        }
    </script>
    <h1 class="mui-title">设置密码</h1>
</header>

<div class="mui-content">
    <div class="mui-password">
        <p>确认您的交易密码</p>
        <input id="n" class="n" oninput="myFunction(this)" type="number"  pattern="[0-9]*" oninput="if(value.length>1)value=value.slice(0,1)">
        <input class="n" oninput="myFunction(this)" type="number"  pattern="[0-9]*" oninput="if(value.length>1)value=value.slice(0,1)">
        <input class="n" oninput="myFunction(this)" type="number"  pattern="[0-9]*" oninput="if(value.length>1)value=value.slice(0,1)">
        <input class="n" oninput="myFunction(this)" type="number"  pattern="[0-9]*" oninput="if(value.length>1)value=value.slice(0,1)">
        <input class="n" oninput="myFunction(this)" type="number"  pattern="[0-9]*" oninput="if(value.length>1)value=value.slice(0,1)">
        <input id="end" class="n" oninput="myFunction(this)" type="number"  pattern="[0-9]*" oninput="if(value.length>1)value=value.slice(0,1)">
    </div>
</div>
</body>
</html>
<script>
    $(document).ready(function () {
        //第一个获取焦点事件
        $('#n').focus();
        $('.n:not(:first)').attr("disabled","disabled");
    })
    function myFunction(obj) {
        var obj = $(obj)
        //获取当前对象里的值
        var length = obj.val().length
        if(length > 1)
        {
            obj.val(obj.val().substr(0, 1))
        }
        if(obj.attr('id') != 'end')
        {
            obj.attr("disabled","disabled");
        }
        obj.next().removeAttr("disabled");
        obj.next().focus()
        word = '';
        $('.n').each(function () {
            var val = $(this).val()
            if(val == '')
            {
                state=false
            }
            else
            {
                word+= val.toString();
                state = true
            }
        })
        if(state === true)
        {
            var password = getParam('password');
            if(password != word)
            {
                //信息框
                layer.open({
                    content: '两次密码输入不一致'
                    ,btn: '我知道了'
                });
                return false
            }
            else
            {
                $.post("{:U('sheZhiJiaoYiMiMa')}",{word:word},function (rel) {
                    //信息框
                    layer.open({
                        content: rel.msg
                        ,btn: '我知道了'
                    });
                })
            }
        }
    }
    function getParam(paramName) {
        paramValue = "", isFound = !1;
        if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
            arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
            while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
        }
        return paramValue == "" && (paramValue = null), paramValue
    }
    $(document).keyup(function(event){
        //获取当前按键的键值
        //jQuery的event对象上有一个which的属性可以获得键盘按键的键值
        var keycode = event.which;
        //处理回车的情况
        if(keycode == 8)
        {
            $('.n').each(function () {
                var val = $(this).val()
                if(val == '')
                {
                    va.removeAttr("disabled");
                    va.focus()
                    return false;
                }
                va = $(this)
            })
        }
    });
</script>